<%@ include file="/WEB-INF/jspf/directive/taglib.jspf"%>

<html>

<c:set var="title">
	<fmt:message key="payments.title.text" />
</c:set>
<%@ include file="/WEB-INF/jspf/head.jspf"%>

<body>

	<div class="container">
		<c:choose>
			<c:when test="${fn:length(payments) == 0}">
				<h3><fmt:message key="payments.label.nopayments" /></h3>
			</c:when>

			<c:otherwise>
				<h3><fmt:message key="payments.label.yourpayments" />:</h3>
				<table class="table table-bordered">
					<thead>
						<tr>
							<td><fmt:message key="payments.label.payer" /></td>
							<td><fmt:message key="payments.label.receiver" /></td>
							<td><fmt:message key="payments.label.value" /></td>
							<td><fmt:message key="payments.label.date" /></td>
							<td><fmt:message key="payments.label.state" /></td>
							<td><fmt:message key="payments.label.actions" /></td>
						</tr>
					</thead>
					<c:forEach var="payment" items="${sessionScope['payments']}">
						<tr>
							<td><c:choose>
									<c:when test="${payment.payer.user == sessionScope.user}">
										<fmt:message key="payments.label.you" /> <br>
										<c:out value="${payment.payer.id}"></c:out>: 
										<b> <c:out value="${payment.payer.balance}"></c:out> <c:out
												value="${payment.payer.valuta.shortName}"></c:out>
										</b>
									</c:when>
									<c:otherwise>
										<c:out value="${payment.payer.user.login}"></c:out>
										<br>
										<c:out value="${payment.payer.id}"></c:out>
									</c:otherwise>
								</c:choose></td>
							<td><c:choose>
									<c:when test="${payment.reciever.user == sessionScope.user}">
									<fmt:message key="payments.label.you" /> <br>
										<c:out value="${payment.reciever.id}"></c:out>
									</c:when>
									<c:otherwise>
										<c:out value="${payment.reciever.user.login}"></c:out>
										<br>
										<c:out value="${payment.reciever.id}"></c:out>
									</c:otherwise>
								</c:choose></td>
							<td><b><c:out value="${payment.val}"></c:out> <c:out
										value="${payment.payer.valuta.shortName}"></c:out></b></td>
							<td><c:out value="${payment.paymentDate}"></c:out></td>
							<td><c:out value="${payment.paymentState}"></c:out></td>
							<td><c:choose>
									<c:when test="${payment.paymentState == 'OPEN'}">
										<c:if test="${payment.payer.user == sessionScope.user}">
											<form action="controller?command=approovePayment"
												method="post"
												style="margin: 0px; padding: 0px; display: inline;">
												<input name="id" type="hidden"
													value=<c:out value="${payment.id}"></c:out>>
												<button type="submit" class="btn txt-fld">
													<fmt:message key="payments.button.confirm" />
												</button>
											</form>
										</c:if>
										<form action="controller?command=rejectPayment" method="post"
											style="margin: 0px; padding: 0px; display: inline;">
											<input name="id" type="hidden"
												value=<c:out value="${payment.id}"></c:out>>
											<button type="submit" class="btn txt-fld">
												<fmt:message key="payments.button.reject" />
											</button>
										</form>
									</c:when>
									<c:otherwise>
									<fmt:message key="payments.label.noactions" />								
								</c:otherwise>
								</c:choose></td>
						</tr>
					</c:forEach>

				</table>

			</c:otherwise>
		</c:choose>

		<a href="controller?command=browseUserPage"
			class="btn btn-large btn-block">
			<fmt:message key="payments.button.back" />
		</a>

	</div>

</body>
</html>